﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BaseText;
using Srvtools;
using System.Text;

public partial class WorkTime_YearHolidayBatch : System.Web.UI.Page
{
    private Srvtools.WebDataSet dsYearHoliday;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BatchSave.Visible = BatchDel.Visible = BatchDelSpecifiedDays.Visible = BatchDelSpecifiedArgs.Visible = false;

            MasterPage_MasterPage mpg = (MasterPage_MasterPage)this.Page.Master;
            mpg.HelpHref = "~/Help/WorkTime/批添加员工年假.htm";
            mpg.PageName = "批添加员工年假";
            mpg.PicUrl = "";
            mpg.IntiBar();
        }
    }

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WorkTime_YearHolidayBatch));
        this.dsYearHoliday = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.dsYearHoliday)).BeginInit();
        // 
        // WMaster
        // 
        this.dsYearHoliday.Active = true;
        this.dsYearHoliday.AlwaysClose = false;
        this.dsYearHoliday.PacketRecords = 0;
        this.dsYearHoliday.Position = -1;
        this.dsYearHoliday.RemoteName = "Common.InfoInti";
        this.dsYearHoliday.ServerModify = false;
        ((System.ComponentModel.ISupportInitialize)(this.dsYearHoliday)).EndInit();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        switch (ContactTime.SelectedIndex)
        {
            case 1:
                DelHoliDaysInti(DLYearMonth.SelectYear, dptlist.SelectDepmanetId);
                break;
            case 2:
                MinusYearHolidayDaysInti(DLYearMonth.SelectYear, DLYearMonth.SelectMonth, dptlist.SelectDepmanetId);
                break;
            default:
                YearHolidayDaysInti(DLYearMonth.SelectYear, DLYearMonth.SelectMonth, dptlist.SelectDepmanetId);
                break;
        }
    }

    #region 年假作废
    private void DelHoliDaysInti(string year, string dept)
    {
        if (year == null || year.ToString() == "" || year.ToString() == "0")
        {
            ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('请选择正确的年份')", true);
            return;
        }

        if (dept == null || dept.ToString() == "" || dept.ToString() == "0")
        {
            dept = " <> " + dept;
        }
        else
        {

            dept = " like '" + dept + "%'";


        }
        BatchDel.Visible = Convert.ToInt32(year) < DateTime.Now.Year;
        BatchSave.Visible = BatchDelSpecifiedDays.Visible = BatchDelSpecifiedArgs.Visible = false;

        DataTable dt = DelYearHolidayDaysDataTable(year, dept);
        wgvMaster.DataSource = dt;
        wgvMaster.DataBind();
    }

    private DataTable DelYearHolidayDaysDataTable(string year, string dept)
    {
        StringBuilder sbr = new StringBuilder();
        StringBuilder sbrd = new StringBuilder();

        sbr.Append("SELECT  Employees.EmployeeID, Employees.EmpName,Department.DepartmentName, Employees.Accession,");
        sbr.Append(" case when WorkTimeDate IS NULL then Accession");
        sbr.Append(" else WorkTimeDate end AS 'WorkTimeDate'");
        sbr.Append(" FROM Employees");
        sbr.Append(" left join Department on (Employees.DepartmentId = Department.DepartmentId) ");
        sbr.Append(" WHERE Employees.EmpStatus = 1 And Department.DepartmentId " + dept);

        sbrd.Append("select Employees.EmployeeID,SUM(WorkTime_YearHoliday.Days) AS DAYS");
        sbrd.Append(" from WorkTime_YearHoliday");
        sbrd.Append(" left join Employees on (Employees.EmployeeID=WorkTime_YearHoliday.EmployeeID)");
        sbrd.Append(" left join Department on (Employees.DepartmentId = Department.DepartmentId)");
        sbrd.Append(" WHERE Employees.EmpStatus = 1 And Department.DepartmentId " + dept + " And Years='" + year + "'");
        sbrd.Append(" group by Employees.EmployeeID,Accession,WorkTimeDate");
        sbrd.Append(" order by Employees.EmployeeID");


        InitializeComponent();

        DataTable Edt = dsYearHoliday.Execute(sbr.ToString()).Tables[0];
        DataTable Ydt = dsYearHoliday.Execute(sbrd.ToString()).Tables[0];

        DataTable NewTable = MakeNewWTable();

        for (int i = 0; i < Edt.Rows.Count; i++)
        {
            DataRow SR = NewTable.NewRow();
            SR["Eid"] = Edt.Rows[i]["EmployeeID"];
            SR["Ename"] = Edt.Rows[i]["EmpName"];
            SR["Dname"] = Edt.Rows[i]["DepartmentName"];

            if (Edt.Rows[i]["WorkTimeDate"] != null && Edt.Rows[i]["WorkTimeDate"].ToString() != "")
            {
                SR["WorkTimeDate"] = Convert.ToDateTime(Edt.Rows[i]["WorkTimeDate"]).ToString("yyyy-MM");
            }
            else
            {
                if (Edt.Rows[i]["Accession"] != null && Edt.Rows[i]["Accession"].ToString() != "")
                {
                    SR["WorkTimeDate"] = Convert.ToDateTime(Edt.Rows[i]["Accession"]).ToString("yyyy-MM");
                }
                else
                {
                    SR["WorkTimeDate"] = DateTime.Now.ToString("yyyy-MM");
                }
            }


            SR["HaveDay"] = 0;
            for (int j = 0; j < Ydt.Rows.Count; j++)
            {
                if (Edt.Rows[i]["EmployeeID"].ToString() == Ydt.Rows[j]["EmployeeID"].ToString())
                {
                    SR["HaveDay"] = Convert.ToSingle(Ydt.Rows[j]["DAYS"].ToString());
                    break;
                }
            }

            SR["DoDay"] = Convert.ToSingle(SR["HaveDay"]) > 0 ? Convert.ToSingle(SR["HaveDay"]) * -1 : 0;


            SR["AccTime"] = GeyWorkTime(Convert.ToDateTime(SR["WorkTimeDate"]), Convert.ToDateTime(year + " - " + DateTime.Now.Month + "-" + DateTime.Now.Day));

            NewTable.Rows.Add(SR);
        }

        return NewTable;

        //return null;
    }

    #endregion

    #region 年假添加
    private void YearHolidayDaysInti(string year, string month, string dept)
    {

        if (year == null || year.ToString() == "" || year.ToString() == "0" ||
            month == null || month.ToString() == "" || month.ToString() == "0")
        {
            ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('请选择正确的年份和月份！')", true);
            return;
        }

        if (dept == null || dept.ToString() == "" || dept.ToString() == "0")
            dept = " <> 0";
        else
            dept = " like '" + dept + "%'";

        BatchSave.Visible = int.Parse(year) >= DateTime.Now.Year;
        BatchDel.Visible = BatchDelSpecifiedDays.Visible = BatchDelSpecifiedArgs.Visible = false;

        DataTable dt = GetYearHolidayDaysDataTable(year, month, dept);
        wgvMaster.DataSource = dt;
        wgvMaster.DataBind();

    }

    private DataTable GetYearHolidayDaysDataTable(string year, string month, string dept)
    {
        StringBuilder sbr = new StringBuilder();
        StringBuilder sbrd = new StringBuilder();
        string SelDate = year + "-" + month + "-1";

        sbr.Append("SELECT  Employees.EmployeeID, Employees.EmpName,Department.DepartmentName, Employees.Accession,");
        sbr.Append(" case when WorkTimeDate IS NULL then Accession");
        sbr.Append(" else WorkTimeDate end AS 'WorkTimeDate'");
        sbr.Append(" FROM Employees");
        sbr.Append(" left join Department on (Employees.DepartmentId = Department.DepartmentId) ");
        sbr.Append(" WHERE Employees.EmpStatus = 1 And Department.DepartmentId " + dept);

        sbrd.Append("select Employees.EmployeeID,SUM(WorkTime_YearHoliday.Days) AS DAYS");
        sbrd.Append(" from WorkTime_YearHoliday");
        sbrd.Append(" left join Employees on (Employees.EmployeeID=WorkTime_YearHoliday.EmployeeID)");
        sbrd.Append(" left join Department on (Employees.DepartmentId = Department.DepartmentId)");
        sbrd.Append(" WHERE [DataType]=1 and Employees.EmpStatus = 1 And Department.DepartmentId " + dept + " And Years='" + year + "'");
        sbrd.Append(" group by Employees.EmployeeID,Accession,WorkTimeDate");
        sbrd.Append(" order by Employees.EmployeeID");


        InitializeComponent();

        DataTable Edt = dsYearHoliday.Execute(sbr.ToString()).Tables[0];
        DataTable Ydt = dsYearHoliday.Execute(sbrd.ToString()).Tables[0];

        DataTable NewTable = MakeNewWTable();

        for (int i = 0; i < Edt.Rows.Count; i++)
        {

            DataRow SR = NewTable.NewRow();
            SR["Eid"] = Edt.Rows[i]["EmployeeID"];
            SR["Ename"] = Edt.Rows[i]["EmpName"];
            SR["Dname"] = Edt.Rows[i]["DepartmentName"];

            if (Edt.Rows[i]["WorkTimeDate"] != null && Edt.Rows[i]["WorkTimeDate"].ToString() != "")
            {
                SR["WorkTimeDate"] = Convert.ToDateTime(Edt.Rows[i]["WorkTimeDate"]).ToString("yyyy-MM");
            }
            else
            {
                if (Edt.Rows[i]["Accession"] != null && Edt.Rows[i]["Accession"].ToString() != "")
                {
                    SR["WorkTimeDate"] = Convert.ToDateTime(Edt.Rows[i]["Accession"]).ToString("yyyy-MM");
                }
                else
                {
                    SR["WorkTimeDate"] = DateTime.Now.ToString("yyyy-MM");
                }
            }


            try
            {
                SR["Accession"] = Convert.ToDateTime(Edt.Rows[i]["Accession"]).ToString("yyyy-MM-dd");

            }
            catch
            {
                SR["Accession"] = DateTime.Now.ToString("yyyy-MM-dd");

            }

            SR["HaveDay"] = 0;
            for (int j = 0; j < Ydt.Rows.Count; j++)
            {
                if (Edt.Rows[i]["EmployeeID"].ToString() == Ydt.Rows[j]["EmployeeID"].ToString())
                {
                    SR["HaveDay"] = Convert.ToSingle(Ydt.Rows[j]["DAYS"].ToString());
                    break;
                }
            }
            SR["AccTime"] = GeyWorkTime(Convert.ToDateTime(SR["WorkTimeDate"]), Convert.ToDateTime(SelDate));
            try
            {
                SR["DoDay"] = YearHolidayDays(Convert.ToSingle(SR["HaveDay"]), Convert.ToInt32(month), Convert.ToInt32(Math.Floor(Convert.ToDouble(SR["AccTime"]))), Convert.ToInt32(Convert.ToDateTime(Edt.Rows[i]["WorkTimeDate"]).Month));
            }
            catch
            { }
            if (month != "1")
            {
                int toyear = Convert.ToInt32(year);
                int tomonth = Convert.ToInt32(month);

                int useryear = Convert.ToDateTime(SR["WorkTimeDate"]).Year;
                int usermonth = Convert.ToDateTime(SR["WorkTimeDate"]).Month;


                //和当前比较
                int backm = toResult(Convert.ToDateTime(toyear + "-" + month + "-1"), Convert.ToDateTime(useryear + "-" + usermonth + "-1"), "y")[0];

                //和1月比较
                int backf = toResult(Convert.ToDateTime(toyear + "-1-1"), Convert.ToDateTime(useryear + "-" + usermonth + "-1"), "y")[0];



                if ((backf == 0 && backm == 1) || (backf == 9 && backm == 10) || (backf == 19 && backm == 20))
                {
                    NewTable.Rows.Add(SR);
                }

            }
            else
            {
                NewTable.Rows.Add(SR);
            }
        }
        return NewTable;

    }

    #endregion

    #region 年假统扣
    private void MinusYearHolidayDaysInti(string year, string month, string dept)
    {
        if (year == null || year.ToString() == "" || year.ToString() == "0" ||
            month == null || month.ToString() == "" || month.ToString() == "0")
        {
            ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('请选择正确的年份和月份！')", true);
            return;
        }

        if (dept == null || dept.ToString() == "" || dept.ToString() == "0")
            dept = " <> 0";
        else
            dept = " like '" + dept + "%'";

        float days;
        if (!float.TryParse(txtDayCount.Text, out days))
        {
            ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('请输入正确的天数！')", true);
            return;
        }
        if (days > 0)
        {
            txtDayCount.Text = "-" + txtDayCount.Text;
            days = 0 - days;
        }

        BatchDelSpecifiedDays.Visible = BatchDelSpecifiedArgs.Visible = int.Parse(year) <= DateTime.Now.Year;
        BatchDel.Visible = BatchSave.Visible = false;

        DataTable dt = MinusYearHolidayDaysDataTable(year, month, dept, days);
        wgvMaster.DataSource = dt;
        wgvMaster.DataBind();
    }

    private DataTable MinusYearHolidayDaysDataTable(string year, string month, string dept, float days)
    {
        StringBuilder sbr = new StringBuilder();
        StringBuilder sbrd = new StringBuilder();
        string SelDate = year + "-" + month + "-1";

        sbr.Append("SELECT  Employees.EmployeeID, Employees.EmpName,Department.DepartmentName, Employees.Accession,");
        sbr.Append(" case when WorkTimeDate IS NULL then Accession");
        sbr.Append(" else WorkTimeDate end AS 'WorkTimeDate'");
        sbr.Append(" FROM Employees");
        sbr.Append(" left join Department on (Employees.DepartmentId = Department.DepartmentId) ");
        sbr.Append(" WHERE Employees.EmpStatus = 1 And Department.DepartmentId " + dept);

        sbrd.Append("select Employees.EmployeeID,SUM(WorkTime_YearHoliday.Days) AS DAYS");
        sbrd.Append(" from WorkTime_YearHoliday");
        sbrd.Append(" left join Employees on (Employees.EmployeeID=WorkTime_YearHoliday.EmployeeID)");
        sbrd.Append(" left join Department on (Employees.DepartmentId = Department.DepartmentId)");
        sbrd.Append(" WHERE Employees.EmpStatus = 1 And Department.DepartmentId " + dept + " And Years='" + year + "'");
        sbrd.Append(" group by Employees.EmployeeID,Accession,WorkTimeDate");
        sbrd.Append(" order by Employees.EmployeeID");


        InitializeComponent();

        DataTable Edt = dsYearHoliday.Execute(sbr.ToString()).Tables[0];
        DataTable Ydt = dsYearHoliday.Execute(sbrd.ToString()).Tables[0];

        DataTable NewTable = MakeNewWTable();

        for (int i = 0; i < Edt.Rows.Count; i++)
        {
            DataRow SR = NewTable.NewRow();
            SR["Eid"] = Edt.Rows[i]["EmployeeID"];
            SR["Ename"] = Edt.Rows[i]["EmpName"];
            SR["Dname"] = Edt.Rows[i]["DepartmentName"];

            if (Edt.Rows[i]["WorkTimeDate"] != null && Edt.Rows[i]["WorkTimeDate"].ToString() != "")
            {
                SR["WorkTimeDate"] = Convert.ToDateTime(Edt.Rows[i]["WorkTimeDate"]).ToString("yyyy-MM");
            }
            else
            {
                if (Edt.Rows[i]["Accession"] != null && Edt.Rows[i]["Accession"].ToString() != "")
                {
                    SR["WorkTimeDate"] = Convert.ToDateTime(Edt.Rows[i]["Accession"]).ToString("yyyy-MM");
                }
                else
                {
                    SR["WorkTimeDate"] = DateTime.Now.ToString("yyyy-MM");
                }
            }


            SR["HaveDay"] = 0;
            for (int j = 0; j < Ydt.Rows.Count; j++)
            {
                if (Edt.Rows[i]["EmployeeID"].ToString() == Ydt.Rows[j]["EmployeeID"].ToString())
                {
                    SR["HaveDay"] = Convert.ToSingle(Ydt.Rows[j]["DAYS"].ToString());
                    break;
                }
            }

            SR["DoDay"] = days;

            SR["AccTime"] = GeyWorkTime(Convert.ToDateTime(SR["WorkTimeDate"]), Convert.ToDateTime(SelDate));

            NewTable.Rows.Add(SR);
        }

        return NewTable;
    }

    #endregion

    private string GeyWorkTime(DateTime wtd, DateTime std)
    {
        try
        {
            TimeSpan ts1 = new TimeSpan(wtd.Ticks);
            TimeSpan ts2 = new TimeSpan(std.Ticks);

            TimeSpan ts = ts2.Subtract(ts1);
            float day = ts.Days;
            return (day / 365).ToString("f1");

        }
        catch
        {
            return "0";
        }
    }

    public int[] toResult(DateTime d1, DateTime d2, string type)
    {
        #region 数据初始化
        DateTime max;
        DateTime min;
        int year;
        int month;
        int tempYear, tempMonth;
        if (d1 > d2)
        {
            max = d1;
            min = d2;
        }
        else
        {
            max = d2;
            min = d1;
        }
        tempYear = max.Year;
        tempMonth = max.Month;
        if (max.Month < min.Month)
        {
            tempYear--;
            tempMonth = tempMonth + 12;
        }
        year = tempYear - min.Year;
        month = tempMonth - min.Month;
        #endregion
        #region 按条件计算
        if (type == "d")
        {
            TimeSpan ts = max - min;
            return new int[] { ts.Days };
        }
        if (type == "m")
        {
            return new int[] { month + year * 12 };
        }
        if (type == "y")
        {
            return new int[] { year };
        }
        return new int[] { year, month };
        #endregion
    }


    /// <summary>
    /// 取得应休年假天数
    /// </summary>
    /// <param name="Inyears"></param>
    /// <returns></returns>
    private Single YearHolidayDays(Single haveday, int month, int worktime, int workmonth)
    {
        //根据工龄获得年假天数
        if (worktime >= 1 && worktime < 10)
        {
            worktime = 5;
        }
        else if (worktime >= 10 && worktime < 20)
        {
            worktime = 10;
        }
        else if (worktime >= 20)
        {
            worktime = 15;
        }
        else
        {
            worktime = 0;
        }

        if (month == 1)
        {
            return haveday <= 0 ? worktime : 0;
        }
        else
        {
            string addday;
            //小数三入五，八入十
            string day = Convert.ToString(Convert.ToDouble(12 - workmonth) / 12 * 5);
            string[] days = day.Split('.');
            if (days.Length > 1)
            {
                int pointnum = Convert.ToInt32(days[1].Substring(0, 1));
                if (pointnum >= 5 && pointnum <= 9)
                {
                    addday = Convert.ToString(Convert.ToInt32(days[0]) + 1);
                }
                else
                {
                    addday = days[0];
                }
                //if (pointnum >= 0 && pointnum < 3)
                //{
                //    addday = days[0];
                //}
                //else if (pointnum >= 3 && pointnum <= 7)
                //{
                //    addday = days[0] + ".5";
                //}
                //else
                //{
                //    addday = Convert.ToString(Convert.ToInt32(days[0]) + 1);
                //}
            }
            else
            {
                addday = day;
            }

            //以有天数大于应添加天数返回0
            if (haveday >= Convert.ToSingle(addday) + worktime)
            {
                return 0;
            }
            else
            {
                return Convert.ToSingle(addday) + worktime - 5 - haveday;
            }

        }

    }


    private DataTable MakeNewWTable()
    {
        DataTable WTable = new DataTable("EmpYearTable");
        {
            WTable.Columns.Add(new DataColumn("Eid", typeof(Int32)));
            WTable.Columns.Add(new DataColumn("Ename", typeof(string)));
            WTable.Columns.Add(new DataColumn("Dname", typeof(string)));
            WTable.Columns.Add(new DataColumn("Accession", typeof(string)));
            WTable.Columns.Add(new DataColumn("WorkTimeDate", typeof(string)));
            WTable.Columns.Add(new DataColumn("AccTime", typeof(string)));
            WTable.Columns.Add(new DataColumn("HaveDay", typeof(Single)));
            WTable.Columns.Add(new DataColumn("DoDay", typeof(Single)));
        }
        return WTable;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void BatchDel_Click(object sender, EventArgs e)
    {
        string Empid;
        string DYear = DLYearMonth.SelectYear;

        ArrayList sqlarr = new ArrayList();

        for (int i = 0; i < wgvMaster.Rows.Count; i++)
        {
            ZLTextBox AddHD = (ZLTextBox)wgvMaster.Rows[i].FindControl("DoDay");
            if (AddHD != null)
            {
                if (Single.Parse(AddHD.Text) != 0)
                {
                    Empid = wgvMaster.Rows[i].Cells[0].Text;

                    sqlarr.Add("insert WorkTime_YearHoliday  ( [EmployeeId] ,[Years], [Days] ,[DataType],[Remark] ) values ( " + Empid + " , " + DYear + " , " + AddHD.Text + " ,22 ,'" + DateTime.Now.ToString("yyyy-MM-dd") + ",批量作废休假')");


                }
            }
        }
        object[] objParm = new object[] { sqlarr };
        object[] ret = CliUtils.CallMethod("Common", "SqlTran", objParm);

        if ((bool)ret[1])
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('全部导入成功！');", true);
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('全部导入失败！');", true);
        }

        DelHoliDaysInti(DLYearMonth.SelectYear, dptlist.SelectDepmanetId);

    }

    protected void BatchSave_Click(object sender, EventArgs e)
    {
        string Empid;
        string DYear = DLYearMonth.SelectYear;
        string DMonth = DLYearMonth.SelectMonth;
        ArrayList sqlarr = new ArrayList();

        for (int i = 0; i < wgvMaster.Rows.Count; i++)
        {
            ZLTextBox AddHD = (ZLTextBox)wgvMaster.Rows[i].FindControl("DoDay");
            if (AddHD != null && !string.IsNullOrEmpty(AddHD.Text))
            {
                if (Single.Parse(AddHD.Text) != 0)
                {
                    Empid = wgvMaster.Rows[i].Cells[0].Text;
                    if (DMonth != "1")
                    {
                        sqlarr.Add("insert WorkTime_YearHoliday  ( [EmployeeId] ,[Years], [Days] ,[DataType],[Remark] ) values ( " + Empid + " , " + DYear + " , " + AddHD.Text + " ,1 ,'" + DateTime.Now.ToString("yyyy-MM-dd") + ",批量导入年假补差')");
                    }
                    else
                    {
                        sqlarr.Add("insert WorkTime_YearHoliday  ( [EmployeeId] ,[Years], [Days] ,[DataType],[Remark] ) values ( " + Empid + " , " + DYear + " , " + AddHD.Text + " ,1 ,'" + DateTime.Now.ToString("yyyy-MM-dd") + ",批量导入年假')");
                    }
                }
            }
        }
        object[] objParm = new object[] { sqlarr };
        object[] ret = CliUtils.CallMethod("Common", "SqlTran", objParm);

        if ((bool)ret[1])
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('全部导入成功！');", true);
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('全部导入失败！');", true);
        }

        YearHolidayDaysInti(DLYearMonth.SelectYear, DLYearMonth.SelectMonth, dptlist.SelectDepmanetId);
    }

    protected void BatchDelSpecifiedDays_Click(object sender, EventArgs e)
    {
        string DYear = DLYearMonth.SelectYear;
        string remark = txtRemark.Text;

        ArrayList sqlarr = new ArrayList();

        for (int i = 0; i < wgvMaster.Rows.Count; i++)
        {
            ZLTextBox AddHD = (ZLTextBox)wgvMaster.Rows[i].FindControl("DoDay");
            if (AddHD != null && !string.IsNullOrEmpty(AddHD.Text))
            {
                float doDay;
                if (float.TryParse(AddHD.Text, out doDay) && doDay != 0)
                {
                    sqlarr.Add("insert WorkTime_YearHoliday  ( [EmployeeId] ,[Years], [Days] ,[DataType],[Remark] ) values ( " + wgvMaster.Rows[i].Cells[0].Text + " , " + DYear + " , " + AddHD.Text + " ,22 ,'" + DateTime.Now.ToString("yyyy-MM-dd") + "," + remark + "')");
                }
            }
        }
        object[] objParm = new object[] { sqlarr };
        object[] ret = CliUtils.CallMethod("Common", "SqlTran", objParm);

        if ((bool)ret[1])
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('全部导入成功！');", true);
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('全部导入失败！');", true);
        }

        MinusYearHolidayDaysInti(DLYearMonth.SelectYear, DLYearMonth.SelectMonth, dptlist.SelectDepmanetId);
    }
}
